<?php 
if($_SERVER['REQUEST_METHOD'] == 'POST'){
	if(isset($_SESSION['carts'])){
		$carts	=	$_SESSION['carts'];
		$items	=	$_POST['item'];
		$num	=	$_POST['num'];
		foreach($carts as $k_c => $cart){
			if(intval($num[$k_c]) > 0){
				$_SESSION['carts'][$k_c]['num']	=	$num[$k_c];
			}
		}
	}
}
?>
<form method="post" action="">
<div class="cart">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
	<th>STT</th>
	<th>Ten sach</th>
	<th>So luong</th>
	<th>Gia</th>
	<th>Thanh tien</th>
	<th>Xoa</th>
</tr>
<?php 
if(isset($_SESSION['carts']) && count($_SESSION['carts']) > 0):
$carts	=	$_SESSION['carts'];
$total	=	0;
foreach($carts as $k => $cart):
?>
<tr>
	<td><?php echo ($k+1);?></td>
	<td><?php echo $cart['id'];?></td>
	<td>
		<input style="width: 40px; text-align: center;" name="num[]" value="<?php echo $cart['num'];?>"/>
		<input type="hidden" name="item[]" value="<?php echo $k;?>"/>
	</td>
	<td><?php echo number_format($cart['price'],2);?></td>
	<td><?php echo number_format(($cart['price']*$cart['num']),2);?></td>
	<td>
		<a href="index.php?act=del_cart&item=<?php echo $k;?>"><img src="images/del.png"/></a>
	</td>
</tr>
<?php $total+=($cart['price']*$cart['num']);?>
<?php endforeach;?>
<tr>
	<td colspan="4"></td>
	<td><?php echo number_format($total,2);?></td>
	<td>&nbsp;</td>
</tr>
<tr>
	<td colspan="6">
	<input type="submit" value="Cập nhật"/>
	<input type="button" onclick="location.href='index.php?act=booking';" value="Đặt hàng"/>
	</td>
</tr>
<?php else:?>
<tr>
	<td><b>Khong co sach trong gio hang!</b></td>
</tr>
<?php endif;?>
</table>
</div>
</form>
